package ooday04;

public class Test {
    public static void main(String[] args) {
//        Master master=new Master();
//        Animal dog=new Dog("小黑", 2, "黑");
//        Animal chick=new Chick("小金",4,"金");
//        Animal fish=new Fish("小花",2,"花");
//        master.feed(dog);
//        master.feed(chick);
//        master.feed(fish);


        Animal[] animals = new Animal[5];
        animals[0] = new Dog("小黑", 2, "黑");
        animals[1] = new Dog("小白", 3, "白");
        animals[2] = new Chick("小金", 1, "金");
        animals[3] = new Chick("小花", 2, "花");
        animals[4] = new Fish("小灰", 3, "灰");
        for(int i=0;i<animals.length;i++){ //遍历所有动物
            System.out.println(animals[i].name); //输出每个动物的名字
            animals[i].eat();   //每个动物吃饭
            animals[i].drink(); //每个动物喝水

            if(animals[i] instanceof Dog){ //若为Dog类型
                Dog dog = (Dog)animals[i];
                dog.lookHouse();
            }
            if(animals[i] instanceof Chick){ //若为Chick类型
                Chick chick = (Chick)animals[i];
                chick.layEggs();
            }
            if(animals[i] instanceof Swim){ //若能游泳(实现Swim接口的)
                Swim s = (Swim)animals[i];
                s.swim();
            }
        }
    }
}
